﻿
using StaffingSystem.EF;
using StaffingSystem.Models;
using StaffingSystem.Tool;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace StaffingSystem.Controllers
{
    public class AccountController : Controller
    {
        
        private JsonResult result;
        public ActionResult Login()
        {
            return View();
        }
        [HttpPost]

        public ActionResult Login(LoginModel model)
        {
            Management management = new Management();
            Loginon login = management.Loginon.FirstOrDefault(m => m.JobNumber == model.UserName && m.PassWord == model.UserPass);         
            if (login != null)
            {
                HttpContext.Session["Time"] = login.LastTime;
                HttpContext.Session["JobNumber"] = login;
                login.LastTime = DateTime.Now;
                //Loginon member = management.Loginon.Find(model.UserName);
                management.Entry<Loginon>(login).State = EntityState.Modified;
                management.SaveChanges();
                result = DataHelper.GetResult(ExecuteState.Succeed, "登录成功,正在进入系统，请稍等...", "");
            }
            else
            {
                result = DataHelper.GetResult(ExecuteState.Failed, "用户名或密码不正确！", "");
            }

            return result;



        }
        // GET: Account
        public ActionResult Index()
        {
            Loginon login = Session["JobNumber"] as Loginon;
            ViewData["Name"] = login.JobNumber;
            ViewData["Time"] = Session["Time"].ToString();
            return View();
        }
        /// <summary>
        /// 基本信息页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Information()
        {
            return View();
        }
    }
}